package com.qf.dao.impl;

import com.qf.dao.CategoryDao;
import com.qf.domain.EBookCategory;
import com.qf.utils.DataSourceUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * 2020/12/9 9:51
 *
 * @author：Lixubiao
 */
public class CategoryDaoImpl implements CategoryDao {
    QueryRunner qr=new QueryRunner(DataSourceUtils.getDataSource());
    @Override
    public List<EBookCategory> selectCategory() {
        String sql="select id,name from ebook_category ";
        try {
            return qr.query(sql,new BeanListHandler<>(EBookCategory.class));
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            throw new RuntimeException("查询失败");
        }
    }
}
